import { readonly } from 'vue'
import { defineStore, storeToRefs } from 'pinia'
import { useAppStore } from '@/store/app'
import { useAuthRouteStore } from '@/store/auth-route'
import { useDialogStore } from '@/store/dialog'
import { AUTH_ROUTES } from '@/constant'

export const useAuthDialogStore = defineStore('authDailog', () => {
  const { authDialog } = storeToRefs(useDialogStore())
  const authRouteStore = useAuthRouteStore()
  const { to } = authRouteStore

  const appStore = useAppStore()
  const { toggleViewerExpand } = appStore

  function open(route = AUTH_ROUTES.LOGIN) {
    authDialog.value = true
    toggleViewerExpand(true)
    to(route)
  }

  function close() {
    authDialog.value = false
  }

  return { isOpen: readonly(authDialog), open, close }
})
